{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "vscode": {
     "languageId": "plaintext"
    }
   },
   "outputs": [],
   "source": [
    "def find_factors(n):\n",
    "    \"\"\"找出n的所有因子（不包括n本身）\"\"\"\n",
    "    factors = []\n",
    "    for i in range(1, n):\n",
    "        if n % i == 0:\n",
    "            factors.append(i)\n",
    "    return factors\n",
    "\n",
    "def is_perfect_number(n):\n",
    "    \"\"\"检查n是否为完数\"\"\"\n",
    "    factors = find_factors(n)\n",
    "    return sum(factors) == n\n",
    "\n",
    "def find_perfect_numbers(limit):\n",
    "    \"\"\"找出limit以内的所有完数\"\"\"\n",
    "    perfect_numbers = []\n",
    "    for num in range(1, limit + 1):\n",
    "        if is_perfect_number(num):\n",
    "            perfect_numbers.append(num)\n",
    "    return perfect_numbers\n",
    "\n",
    "# 找出1000以内的所有完数\n",
    "perfect_numbers_within_1000 = find_perfect_numbers(1000)\n",
    "print(\"1000以内的所有完数:\", perfect_numbers_within_1000)"
   ]
  }
 ],
 "metadata": {
  "language_info": {
   "name": "python"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
